package com.easpeed.elevator.base;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.baidu.location.LocationClient;
import com.baidu.mapapi.SDKInitializer;
import com.bigyu.utils.Logger;
import com.blankj.utilcode.util.Utils;
import com.danikula.videocache.HttpProxyCacheServer;
import com.easpeed.comon.database.DataBaseCommon;
import com.easpeed.comon.utils.ActivityLifecycleHelper;
import com.easpeed.comon.utils.ImageUtils;
import com.easpeed.comon.utils.SocketHelper;
import com.easpeed.elevator.utils.MyUncaughtExceptionHandler;


/**
 * Created by Taylor on 2016/12/15.
 */
public class MyApplication extends Application {

    /**
     * 全局上下文
     */
    public static Context context;
    private int minX, minY, maxX, maxY, x, y, tnum;
    public SharedPreferences sp;
    private boolean rex, rey;

    private HttpProxyCacheServer proxy;

    public static boolean isFan = true;


    public static HttpProxyCacheServer getProxy(Context context) {
        MyApplication app = (MyApplication) context.getApplicationContext();
        return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy;
    }

    private HttpProxyCacheServer newProxy() {
        return new HttpProxyCacheServer.Builder(this)
                .maxCacheSize(1024 * 1024 * 1024)       // 1 Gb for cache
                .maxCacheFilesCount(10)
                .build();
    }


    @Override
    public void onCreate() {
        super.onCreate();


//        Logger.init(this);
        Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
        DataBaseCommon.Companion.init(this);
        ImageUtils.Companion.init(this);
        SDKInitializer.setAgreePrivacy(this, true);
        LocationClient.setAgreePrivacy(true);
        SDKInitializer.initialize(this);
        SocketHelper.init(this);
        ActivityLifecycleHelper.initLifeline(this);
        context = getApplicationContext();
        Utils.init(this);
        sp = PreferenceManager.getDefaultSharedPreferences(this);

    }


}
